In [1]:
from pymatgen.ext.matproj import MPRester
from pymatgen.analysis.phase_diagram import PhaseDiagram, PDPlotter
%matplotlib inline

Generating the phase diagram

To generate a phase diagram, we obtain entries from the Materials Project and call the PhaseDiagram class in pymatgen.


In [2]:
#This initializes the REST adaptor. You may need to put your own API key in as an arg.
a = MPRester()

#Entries are the basic unit for thermodynamic and other analyses in pymatgen.
#This gets all entries belonging to the Ca-C-O system.
entries = a.get_entries_in_chemsys(['Ca', 'C', 'O'])

#With entries, you can do many sophisticated analyses, like creating phase diagrams.
pd = PhaseDiagram(entries)

Plotting the phase diagram

To plot a phase diagram, we send our phase diagram object into the PDPlotter class.


In [3]:
#Let's show all phases, including unstable ones
plotter = PDPlotter(pd, show_unstable=True)
plotter.show()


Calculating energy above hull and other phase equilibria properties

To perform more sophisticated analyses, use the PDAnalyzer object.


In [4]:
import collections

data = collections.defaultdict(list)
for e in entries:
    decomp, ehull = pd.get_decomp_and_e_above_hull(e)
    data["Materials ID"].append(e.entry_id)
    data["Composition"].append(e.composition.reduced_formula)
    data["Ehull"].append(ehull)    
    data["Decomposition"].append(" + ".join(["%.2f %s" % (v, k.composition.formula) for k, v in decomp.items()]))

from pandas import DataFrame
df = DataFrame(data, columns=["Materials ID", "Composition", "Ehull", "Decomposition"])

print(df)


   Materials ID Composition     Ehull                           Decomposition
0        mp-166          Ca  0.013329                                1.00 Ca2
1      mp-10683          Ca  0.396161                                1.00 Ca2
2         mp-21          Ca  0.013583                                1.00 Ca2
3         mp-45          Ca  0.000508                                1.00 Ca2
4    mp-1008498          Ca  0.152771                                1.00 Ca2
5        mp-132          Ca  0.000000                                1.00 Ca2
6     mp-632329           C  0.110332                                1.00 C16
7     mp-568028           C  0.528945                                1.00 C16
8    mp-1008374           C  0.437262                                1.00 C16
9     mp-568286           C  0.000000                                1.00 C16
10    mp-611426           C  0.145308                                1.00 C16
11    mp-683919           C  0.348592                                1.00 C16
12    mp-937760           C  0.003670                                1.00 C16
13    mp-998866           C  2.756837                                1.00 C16
14    mp-569567           C  0.174406                                1.00 C16
15    mp-667273           C  0.388760                                1.00 C16
16    mp-570002           C  0.762539                                1.00 C16
17    mp-990448           C  0.003052                                1.00 C16
18    mp-579909           C  0.944071                                1.00 C16
19    mp-997182           C  0.003585                                1.00 C16
20    mp-568806           C  0.006175                                1.00 C16
21   mp-1018088           C  1.299379                                1.00 C16
22        mp-66           C  0.135631                                1.00 C16
23    mp-606949           C  0.003575                                1.00 C16
24    mp-680372           C  0.407085                                1.00 C16
25    mp-616440           C  0.140564                                1.00 C16
26    mp-568410           C  0.506378                                1.00 C16
27       mp-169           C  0.004413                                1.00 C16
28    mp-624889           C  1.255021                                1.00 C16
29    mp-569517           C  0.145186                                1.00 C16
..          ...         ...       ...                                     ...
53      mp-2482        CaC2  0.022313                     0.67 C16 + 0.33 Ca2
54   mp-1009655        CaC2  0.743834                     0.67 C16 + 0.33 Ca2
55    mp-570697        CaC2  0.762125                     0.67 C16 + 0.33 Ca2
56   mp-1022724        CaC4  0.330530                     0.80 C16 + 0.20 Ca2
57    mp-545512         CaO  0.065085                             1.00 Ca1 O1
58    mp-634859        CaO2  0.007227                   0.33 O8 + 0.67 Ca1 O1
59      mp-2605         CaO  0.000000                             1.00 Ca1 O1
60     mp-11725         CO2  0.011643                              1.00 C4 O8
61    mp-995198         CO2  0.323686                              1.00 C4 O8
62    mp-995196         CO3  3.078212                    0.75 C4 O8 + 0.25 O8
63    mp-556660          CO  0.692016                   0.75 C4 O8 + 0.25 C16
64   mp-1001594        C4O3  0.241118                   0.64 C4 O8 + 0.36 C16
65    mp-556034         CO2  0.028775                              1.00 C4 O8
66    mp-995224         CO2  0.302425                              1.00 C4 O8
67    mp-644607         CO2  0.028281                              1.00 C4 O8
68     mp-11875          CO  0.668938                   0.75 C4 O8 + 0.25 C16
69    mp-561848        C3O2  0.513353                   0.60 C4 O8 + 0.40 C16
70     mp-20066         CO2  0.000000                              1.00 C4 O8
71    mp-995183          CO  0.559450                   0.75 C4 O8 + 0.25 C16
72    mp-641635       CaCO3  1.368847                          1.00 Ca2 C2 O6
73    mp-560265       CaCO3  0.008073                          1.00 Ca2 C2 O6
74      mp-4626       CaCO3  0.024281                          1.00 Ca2 C2 O6
75      mp-3953       CaCO3  0.000000                          1.00 Ca2 C2 O6
76    mp-548403       CaCO3  0.312190                          1.00 Ca2 C2 O6
77    mp-553939       CaCO3  0.013584                          1.00 Ca2 C2 O6
78    mp-556235       CaCO3  0.002015                          1.00 Ca2 C2 O6
79    mp-558543    Ca(CO2)2  0.046302  0.21 C4 O8 + 0.71 Ca2 C2 O6 + 0.07 C16
80    mp-561412       CaCO3  0.007359                          1.00 Ca2 C2 O6
81    mp-696740       CaCO3  2.017768                          1.00 Ca2 C2 O6
82      mp-3205       CaCO3  0.169799                          1.00 Ca2 C2 O6

[83 rows x 4 columns]

In [ ]: